import java.util.HashSet;
import java.util.Set;

class Book {
    private String title;
    private String author;

    public Book(String title, String author) {
        this.title = title;
        this.author = author;
    }

    public String getTitle() {
        return title;
    }

    public String getAuthor() {
        return author;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Book book = (Book) o;
        return title.equals(book.title) && author.equals(book.author);
    }

    @Override
    public int hashCode() {
        int result = title.hashCode();
        result = 31 * result + author.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return  title + '\'' + author ;
    }
}

class User {
    private Set<Book> bookshelf;

    public User() {
        this.bookshelf = new HashSet<>();
    }

    public void addBook(Book book) {
        bookshelf.add(book);
    }

    public void removeBook(Book book) {
        bookshelf.remove(book);
    }

    public void displayBookshelf() {
        System.out.println("书单中的图书：");
        for (Book book : bookshelf) {
            System.out.println(book);
        }
    }

    public int countBooks() {
        return bookshelf.size();
    }
}

public class BookStore {
    public static void main(String[] args) {
        User user = new User();
        Book book1 = new Book("Java编程思想", "Bruce Eckel");
        Book book2 = new Book("Effective Java", "Joshua Bloch");
        Book book3 = new Book("Java核心技术", "Cay S. Horstmann");

        user.addBook(book1);
        user.addBook(book2);
        user.addBook(book3);
        user.addBook(book1); // 重复添加，不会生效

        user.displayBookshelf();
        System.out.println("书单中图书的数量：" + user.countBooks());

        user.removeBook(book2);
        user.displayBookshelf();
        System.out.println("书单中图书的数量：" + user.countBooks());
    }
}







